<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li:nth-child(odd) {
      background-color: green;
    }

    li:nth-child(even) {
      background-color: pink;
    }
  </style>
</head>

<body>
  <ul id="box">
    <!-- <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li> -->
  </ul>
  <script>
    var ary = ['哈哈', 2, 3, '不好', 5]; // 请求的后台数据

    // ['<li>1</li>','<li>2</li>','<li>3</li>','<li>4</li>']
    // '<li>1</li><li>2</li>'

    var box = document.getElementById('box');

    var res = ary.map(function (item, index) {
      return `<li class="${index}">${item}</li>`
    });
    res = res.join('');
    box.innerHTML = res
    console.log(res);







  </script>
</body>

</html>